﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Text;
using System.Windows.Controls;
using System.Windows.Media;

namespace CCF20
{
    public class ButtonBase : WiseLinkWPF.Windows.Controls.RadButton
    {
        public ButtonBase()
        {
            this.Initialized += new EventHandler(ButtonBase_Initialized);
        }

        void ButtonBase_Initialized(object sender, EventArgs e)
        {
            string currentUser = (string)Application.Current.Properties["CurrentUser"];
            if (currentUser.Equals("Admin", StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }
            Button button = (Button)sender;
            
            string permission = (string)Application.Current.Properties["AllowedPermission"];
            
            if ((permission != null) && permission.Contains((string)button.Content))
            {
                button.IsEnabled = true;
            }
            else
            {
                button.IsEnabled = false;
                button.Background = new SolidColorBrush(Colors.White);
                button.Foreground = new SolidColorBrush(Colors.Black);
            }
        }
    }
}
